import configparser

class AppConfig:
    def __init__(self, config_path='config.ini'):
        self.config = configparser.ConfigParser()
        read_files = self.config.read(config_path)
        if not read_files:
            raise FileNotFoundError(f'配置文件 {config_path} 未找到')
        # 检查必要部分
        for section in ['elasticsearch', 'smtp', 'alerting']:
            if section not in self.config:
                raise ValueError(f'配置文件缺少 [{section}] 部分')

    def get_es_config(self):
        return self.config['elasticsearch']

    def get_smtp_config(self):
        return self.config['smtp']

    def get_alerting_config(self):
        return self.config['alerting']

    def get_auth_config(self):
        return self.config['auth']

    def get(self, section, key, default=None):
        return self.config.get(section, key, fallback=default) 